<template>
  <div>
    <div class="dh">
      <van-tabs v-model="tabsName">
        <van-tab title="推荐" name="a" to="/home/indexV/index"></van-tab>
        <van-tab title="活动" name="b"></van-tab>
      </van-tabs>
    </div>

    <van-swipe class="my-swipe" :autoplay="1000">
      <van-swipe-item v-for="item in swiper" :key="item.id">
        <img :src="base + item.pic" alt="" />
      </van-swipe-item>
    </van-swipe>
    <van-sticky>
      <van-tabs v-model="activityName" @click="activityByTypeId">
        <van-tab
          v-for="item in activityTypeName"
          :key="item.id"
          :title="item.typename"
          :name="item.id"
        >
        </van-tab>
      </van-tabs>
    </van-sticky>
    <!-- 加载活动列表 -->
    <van-pull-refresh
      success-text="加载完成"
      v-model="isLoading" @refresh="onRefresh"
    >
      <!-- <div class="kongbai"></div> -->
      <van-list finished-text="我是有底线的">
        <activity-item
          v-for="item in activities"
          :key="item.id"
          :pic="base + item.pic"
          :title="item.title"
          :time="item.time"
          :number="item.number"
          :competition_type="item.competition_type"
          :id="item.id"
        ></activity-item>
      </van-list>
    </van-pull-refresh>
  </div>
</template>

<script>
import Vue from "vue";
import { Swipe, SwipeItem,Toast } from "vant";
import { Tab, Tabs } from "vant";
import httpApi from "@/http";
import { base } from "@/service";
import ActivityItem from "@/components/ActivityItem.vue";

Vue.use(Tab);
Vue.use(Tabs);
Vue.use(Swipe);
Vue.use(SwipeItem);

export default {
  components: { ActivityItem },
  mounted() {
    this.swiperList();
    this.activityTypeNames();
    this.activityByTypeId(1);
  },
  data() {
    return {
      i: 1,
      tabsName: "b",
      activityName: "1",
      activityTypeName: [],
      base,
      swiper: [],
      activities: [],
      isLoading: false,
    };
  },
  methods: {
    onRefresh() {
      setTimeout(() => {
        Toast('刷新成功');
        this.isLoading = false;
      }, 1000);
    },
    activityByTypeId(id) {
      // console.log(id);
      // console.log({ x: window.scrollX, y: window.scrollY });
      window.scrollTo(0, 300);

      httpApi.activityApi
        .activityByTypeId({ activity_type_id: id })
        .then((res) => {
          // console.log("查询类型id对应的活动", res);
          this.activities = res.data.data;
        });
    },

    activityTypeNames() {
      httpApi.activityApi.activityTypeList().then((res) => {
        // console.log("活动类型", res);
        this.activityTypeName = res.data.data;
      });
    },

    swiperList() {
      httpApi.activityApi.activitySwiper().then((res) => {
        // console.log("轮播图", res);
        this.swiper = res.data.data;
      });
    },

  },
};
</script>

<style lang="scss" scoped>
* {
  padding: 0;
  margin: 0;
}
.dh .van-tabs__line {
  background-color: black;
}

.search {
  margin: 20px 0;
  input {
    margin-left: 25px;
    padding-left: 20px;
    width: 80%;
    height: 26px;
    border-radius: 12px;
    border: 1px solid #e5e5e5;
    color: #e5e5e5;
    outline: none;
    font-size: 14px;
    font-weight: 100;
  }
}
.my-swipe {
  width: 375px;
  display: flex;
  overflow: hidden;
  img {
    width: 100%;
    height: 100%;
  }
}
// 最新活动
.title {
  padding: 16px 0 6px;
}

// 热门赛事
.hot {
  width: 375px;
  // display: grid;
  text-align: left;

  .hottw {
    display: inline-block;
    // display: flex;
    margin: 3px 3px;
    box-shadow: 0 0 1px 1px #e5e5e5;
    width: 180px;
    h4 {
      span {
        color: purple;
      }
    }
    img {
      width: 180px;
      height: 100px;
    }
    p {
      line-height: 1.8;
      position: relative;
      font-size: 12px;
      color: gray;
      span {
        position: absolute;
        right: 0;
      }
    }
  }
}

.kongbai {
  height: 30px;
}
</style>
